package com.github.cooingandwooing.common.core.model;

import java.io.Serializable;

import com.github.cooingandwooing.common.core.constant.BizErrorConstant;
import com.github.cooingandwooing.common.core.utils.ErrorCodeUtils;
import lombok.Data;

/**
 * 〈响应对象〉
 *
 * @author Administrator
 * @create 2022/4/27
 * @since 1.0.0
 */
@Data
public class ResponseBean<T> implements Serializable {

    public static final long serialVersionUID = 42L;
    // 响应码
    private String code;
    // 响应信息
    private String message;
    // 响应数据
    private T data;

    private ResponseBean() {
        super();
    }

    private ResponseBean(T data) {
        super();
        this.data = data;
    }

    public ResponseBean(String code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    private static <T> ResponseBean<T> of(String code, String message, T data) {
        return new ResponseBean<T>(code, message, data);
    }

    public static <T> ResponseBean<T> fail(String code, String message) {
        return of(code, message, null);
    }

    public static <T> ResponseBean<T> fail(String code) {
        return fail(code, ErrorCodeUtils.getMessage(code));
    }

    public static <T> ResponseBean<T> seccess(T data) {
        return of(BizErrorConstant.SECCESS, ErrorCodeUtils.getMessage(BizErrorConstant.SECCESS), data);
    }
}